#!/usr/bin/env bash

mysql_ip=${1:?mysql_ip}
mysql_root_pwd=${2:?mysql_pwd}
mysql_port=${3:-3306}
# nacos

host=$4
if [ -z "$host" ]
then
  host='http://dev8.cn:8000/static/ops'
fi

mysql -uroot -p$mysql_root_pwd -P$mysql_port -h$mysql_ip -e "create database nacos"
wget  $host/nacos-db.sql -P /opt/ -N
mysql -uroot -p$mysql_root_pwd -P$mysql_port -h$mysql_ip -Dnacos  < /opt/nacos-db.sql


docker run  --name nacos -d -p 8848:8848 \
  --net mynet --ip 172.72.0.16  \
  -e PREFER_HOST_MODE=hostname \
  -e MODE=standalone \
  -e SPRING_DATASOURCE_PLATFORM=mysql \
  -e MYSQL_SERVICE_HOST=$mysql_ip \
  -e MYSQL_SERVICE_PORT=$mysql_port \
  -e MYSQL_SERVICE_DB_NAME=nacos \
  -e MYSQL_SERVICE_USER=root \
  -e MYSQL_SERVICE_PASSWORD=$mysql_root_pwd \
  nacos/nacos-server
